package com.estar.assistsurvy.activity;

import java.util.ArrayList;
import java.util.List;

import org.litepal.crud.DataSupport;

import com.estar.assistsurvey.entity.ImageVO;
import com.estar.assistsurvy.R;
import com.estar.assistsurvy.adapter.PhotoPreviewAdapter;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.RelativeLayout;

public class PhotoPreviewActivity extends BaseActivity implements OnClickListener,OnItemClickListener{

	private RelativeLayout returnBack;
	private GridView photo_grid;
	private PhotoPreviewAdapter adapter;
	private List<ImageVO> list;
	private String rptNo;
	private Intent intent;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_preview);
		init();
	}
	private void init(){
		intent=getIntent();
		rptNo=intent.getStringExtra("rptNo");
		list=new ArrayList<>();
		if(DataSupport.where("rptNo=?",rptNo).find(ImageVO.class)!=null){
			list=DataSupport.where("rptNo=?",rptNo).find(ImageVO.class);
		}else{
			showShortToast("当前案件没有拍照查勘!");
		}
		
		returnBack=find(R.id.returnBack);
		returnBack.setOnClickListener(this);
		photo_grid=find(R.id.photo_grid);
		adapter=new PhotoPreviewAdapter(list, PhotoPreviewActivity.this);
		photo_grid.setAdapter(adapter);
		photo_grid.setOnItemClickListener(this);
		
	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.returnBack:
			finish();
			break;

		default:
			break;
		}
	}
	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		// TODO Auto-generated method stub
		intent=new Intent(PhotoPreviewActivity.this, PhotoDetailActivity.class);
		intent.putExtra("rptNo", rptNo);
		intent.putExtra("position", position);
		startActivity(intent);
	}
}
